<html>
<head><meta charset="utf-8"><title>Next steps for mutable references in constants · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html">Next steps for mutable references in constants</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202430368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430368">(Jun 30 2020 at 12:55)</a>:</h4>
<p>Hi! <span class="user-mention" data-user-id="124288">@oli</span>  <span class="user-mention" data-user-id="118594">@ecstatic-morse</span> is there something else we can do about <a href="https://github.com/rust-lang/rust/issues/71212">https://github.com/rust-lang/rust/issues/71212</a>?</p>



<a name="202430454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430454">(Jun 30 2020 at 12:56)</a>:</h4>
<p>uh</p>



<a name="202430466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430466">(Jun 30 2020 at 12:56)</a>:</h4>
<p>what's the current state? I forget</p>



<a name="202430517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430517">(Jun 30 2020 at 12:56)</a>:</h4>
<p>ah, just in const fn, forbidden outside</p>



<a name="202430527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430527">(Jun 30 2020 at 12:56)</a>:</h4>
<p>yep</p>



<a name="202430571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430571">(Jun 30 2020 at 12:57)</a>:</h4>
<p>Are you asking what to do about stabilizing <code>&amp;mut</code> in <code>const fn</code> or about what the next steps are for figuring out <code>&amp;mut</code> in const items?</p>



<a name="202430623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430623">(Jun 30 2020 at 12:57)</a>:</h4>
<p>I'm more interested in the second one but working on stabilizing it would be nice</p>



<a name="202430795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430795">(Jun 30 2020 at 12:59)</a>:</h4>
<p>I think a first step would be to do <a href="https://github.com/rust-lang/rust/issues/72396">https://github.com/rust-lang/rust/issues/72396</a></p>



<a name="202430826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430826">(Jun 30 2020 at 12:59)</a>:</h4>
<p>so that we can implement <a href="https://github.com/rust-lang/rust/issues/71212#issuecomment-629793176">https://github.com/rust-lang/rust/issues/71212#issuecomment-629793176</a></p>



<a name="202430980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430980">(Jun 30 2020 at 13:00)</a>:</h4>
<p>TLDR:</p>



<a name="202430983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202430983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202430983">(Jun 30 2020 at 13:00)</a>:</h4>
<blockquote>
<p>We can achieve that by stopping validation when we hit a GlobalAlloc::Static(DefId) allocation. I think that is reasonable -- we already stop there if the DefId is in a different crate, so we cannot rely on this for soundness anyway.</p>
</blockquote>



<a name="202431026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202431026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202431026">(Jun 30 2020 at 13:01)</a>:</h4>
<p>a PR that does just that change would be fine by me</p>



<a name="202431368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202431368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202431368">(Jun 30 2020 at 13:04)</a>:</h4>
<p>OK I think that I get the idea</p>



<a name="202431372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/202431372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#202431372">(Jun 30 2020 at 13:04)</a>:</h4>
<p>more or less</p>



<a name="203683209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683209">(Jul 13 2020 at 07:00)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> so without looking at previous discussion: what about MIR const checking telling apart borrows on "leaked to <code>'static</code>"-scoped "locals" and regular locals?</p>



<a name="203683230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683230">(Jul 13 2020 at 07:00)</a>:</h4>
<p>because borrows on regular locals should be fine, borrowck would prevent them being treated as <code>&amp;'static T</code> / <code>&amp;'static mut T</code></p>



<a name="203683272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683272">(Jul 13 2020 at 07:01)</a>:</h4>
<p>(I hit this in <a href="https://github.com/rust-lang/rust/issues/74283">#74283</a> and ended up making a <code>const fn</code> with no inputs just to compute a value using mutable local state)</p>



<a name="203683323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683323">(Jul 13 2020 at 07:02)</a>:</h4>
<p>maybe we should mark the weirder "locals" like I thought we would a long time ago, instead of having just <code>Storage{Live,Dead}</code> to indicate it</p>



<a name="203683329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683329">(Jul 13 2020 at 07:02)</a>:</h4>
<p>or we can just index the <code>Storage{Live,Dead}</code> for all locals just before const-checking and that'd be that</p>



<a name="203683331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683331">(Jul 13 2020 at 07:02)</a>:</h4>
<p>either way, the information should be there IMO</p>



<a name="203683361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683361">(Jul 13 2020 at 07:03)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> furthermore, we can pretty much just say that if a local has <code>StorageDead</code>, it can be borrowed in a <code>const</code></p>



<a name="203683378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683378">(Jul 13 2020 at 07:03)</a>:</h4>
<p><code>&amp;mut</code> or <code>&amp;</code>+interior mutability</p>



<a name="203683465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683465">(Jul 13 2020 at 07:05)</a>:</h4>
<p>but not if it's missing <code>StorageDead</code> (which may be more conservative than necessary if we have temporaries with no <code>Storage{Live,Dead}</code> but it should still be more useful than the current blanket ban)</p>



<a name="203683991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203683991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203683991">(Jul 13 2020 at 07:14)</a>:</h4>
<p>what does "has <code>StorageDead</code>" mean? ideally it would mean "a <code>StorageDead</code> is guaranteed to be executed after the borrow on any path from the borrow to a <code>Return</code>"</p>



<a name="203684581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203684581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203684581">(Jul 13 2020 at 07:23)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I mean, if it isn't, it's kind of broken. although I agree the current semantics are a bit iffy. in any case, yeah if we can check that more specific predicate, I wouldn't mind it</p>



<a name="203684592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203684592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203684592">(Jul 13 2020 at 07:23)</a>:</h4>
<p>(I just don't know what it would take, compared to just checking that there is <em>any</em> <code>StorageDead</code> at all)</p>



<a name="203684640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203684640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203684640">(Jul 13 2020 at 07:24)</a>:</h4>
<p>I was just saying that "there exists a StorageDead for this local somewhere in this <del>function</del> MIR body (but we may not ever reach it)" is insufficient</p>



<a name="203684651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203684651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203684651">(Jul 13 2020 at 07:24)</a>:</h4>
<p>(since the weird escaping "locals" really could just as well have a flag in their <code>LocalDecl</code>)</p>



<a name="203684662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203684662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203684662">(Jul 13 2020 at 07:24)</a>:</h4>
<p>well, not function, but <code>const</code>/<code>static</code></p>



<a name="203763154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203763154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203763154">(Jul 13 2020 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants/near/203683209">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="124288">oli</span> so without looking at previous discussion: what about MIR const checking telling apart borrows on "leaked to <code>'static</code>"-scoped "locals" and regular locals?</p>
</blockquote>
<p>This would be ideal, but I wasn't sure where I should be looking for this information. If the borrow-checker uses the absence of <code>StorageDead</code> within a <code>const</code>/<code>static</code> initializer to indicate that a borrow of that local can be coerced to <code>'static</code>, It should be fine for const-checking to do the same. I think we don't emit <code>StorageLive</code>/<code>StorageDead</code> for some locals within function bodies (arguments obviously but maybe more?), so I wasn't entirely clear on the semantics.</p>



<a name="203779941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203779941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203779941">(Jul 13 2020 at 22:36)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> the leaked one specifically have <code>StorageLive</code> and no <code>StorageDead</code>, so you can tell them apart from those that don't have any</p>



<a name="203779982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203779982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203779982">(Jul 13 2020 at 22:36)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> however if you want to add a flag to <code>LocalDecl</code>, that should be easy, there is exactly one place where that behavior is triggered, in the building code</p>



<a name="203780044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203780044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203780044">(Jul 13 2020 at 22:37)</a>:</h4>
<p>(it is intentional, otherwise you wouldn't end up with the asymmetry of <code>StorageLive</code> w/o a <code>StorageDead</code> in the first place)</p>



<a name="203780133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203780133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203780133">(Jul 13 2020 at 22:38)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> <span class="user-mention" data-user-id="124288">@oli</span> <span class="user-mention" data-user-id="120791">@RalfJ</span> in case you've never seen this big comment: this is what triggers everything: <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/build/expr/as_temp.rs#L93-L108">https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/build/expr/as_temp.rs#L93-L108</a></p>



<a name="203780202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203780202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203780202">(Jul 13 2020 at 22:40)</a>:</h4>
<p>so you could just as well add this to that:</p>
<div class="codehilite"><pre><span></span><code><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">this</span><span class="p">.</span><span class="n">local_decls</span><span class="p">[</span><span class="n">temp</span><span class="p">].</span><span class="n">leak_to_static</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203781989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203781989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203781989">(Jul 13 2020 at 23:03)</a>:</h4>
<p>Sounds good. <span class="user-mention" data-user-id="132916">@Christian Poveda</span> ^</p>



<a name="203783256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203783256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203783256">(Jul 13 2020 at 23:22)</a>:</h4>
<p>and then we can apply the const-checking borrow restrictions only to those, I doubt there are any restrictions necessary for regular short-lived borrows</p>



<a name="203783282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203783282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203783282">(Jul 13 2020 at 23:22)</a>:</h4>
<p>and miri can assert that whatever behavior it applies right now only happens on a <code>leak_to_static</code> local</p>



<a name="203805437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805437">(Jul 14 2020 at 07:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants/near/203783282">said</a>:</p>
<blockquote>
<p>and miri can assert that whatever behavior it applies right now only happens on a <code>leak_to_static</code> local</p>
</blockquote>
<p>basically we should only be interning leak_to_static locals at the end, is that right?</p>



<a name="203805444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805444">(Jul 14 2020 at 07:24)</a>:</h4>
<p>that might require tracking some extra metadata somewhere, but yes it sounds good</p>



<a name="203805456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805456">(Jul 14 2020 at 07:24)</a>:</h4>
<p>presumably the borrow checker should be made to also use that information, just to make sure everything relies on the same flag</p>



<a name="203805541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805541">(Jul 14 2020 at 07:26)</a>:</h4>
<p>I would use it in combination with what we have today, to catch any assumptions being broken</p>



<a name="203805555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805555">(Jul 14 2020 at 07:27)</a>:</h4>
<p>to be clear, this is <a href="https://github.com/rust-lang/rust/issues/40036">https://github.com/rust-lang/rust/issues/40036</a></p>



<a name="203805591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/203805591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#203805591">(Jul 14 2020 at 07:27)</a>:</h4>
<p>we just don't have to differentiate more than "just a flag on <code>LocalDecl</code>"</p>



<a name="215115572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/215115572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#215115572">(Oct 30 2020 at 16:07)</a>:</h4>
<p>After our recent cleanups around const validation and interning, none of the more complex schemes are necessary. I made a PR (<a href="https://github.com/rust-lang/rust/issues/78578">#78578</a>) that just allows mutable references in all const contexts, and all the static checks trigger where we'd like them to trigger (I also added new tests).</p>



<a name="215189749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/215189749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#215189749">(Oct 31 2020 at 12:36)</a>:</h4>
<p>most of these are dynamic checks though, aren't they? validation and interning certainly are...</p>



<a name="215244791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/215244791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#215244791">(Nov 01 2020 at 13:42)</a>:</h4>
<p>yea, dynamic indeed</p>



<a name="215244795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/215244795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#215244795">(Nov 01 2020 at 13:43)</a>:</h4>
<p>not static. I keep thinking validation is a static thing for some reason</p>



<a name="215260926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Next%20steps%20for%20mutable%20references%20in%20constants/near/215260926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Next.20steps.20for.20mutable.20references.20in.20constants.html#215260926">(Nov 01 2020 at 20:30)</a>:</h4>
<p>that seems like a big departure from the previous strategy of ensuring everything statically (pre-monomorphization)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>